import ajax from "../common/fui-request.js"
import {
	BASE_URL
} from "../_env.js"
import {
	useAuthStore
} from "../store/modules/auth.js"
export const FileApi = {
	/**
	 * 上传
	 */
	upload: (mediaType, file) => {
		const the = this
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: `${BASE_URL}/system/weChat/uploadFile?mediaType=${mediaType}`,
				file,
				header: {
					'Authorization': useAuthStore().token,
				},
				name: 'file',
				success(res) {
					const d = JSON.parse(res.data)
					if (d.code === 200) {
						resolve(d.data)
					} else {
						reject(res.msg)
					}
				},
				fail(err) {
					reject(err)
				}
			})
		})


	},

	/**
	 * 上传微信文件
	 */
	uploadWechatFile: (mediaId) => ajax.get('/system/weChat/minio/uploadFile', {
		data: {
			mediaId
		}
	}),

	/**
	 * 获取文件
	 */
	getFile: (mediaId) => ajax.get('/system/weChat/getFile', {
		data: {
			mediaId
		}

	}),

	/**
	 * 上传微信录音文件
	 */
	upWechatVoice: (mediaId) => ajax.get('/system/weChat/minio/uploadSoundFile', {
		data: {
			mediaId
		}
	}),

	/**
	 * 获取临时录音文件
	 */
	getVoiceFile: (mediaId) => ajax.get('/system/weChat/getSoundFile', {
		data: {
			mediaId
		}
	})

}